package com.xayy.health.ds.controller;

import cn.kawins.base.result.ResultBody;
import com.xayy.health.ds.model.DsModelTrainRecord;
import com.xayy.health.ds.model.DsTaskParamInfo;
import com.xayy.health.ds.model.DsTelemetryData;
import com.xayy.health.ds.service.DsDiagnoseService;
import com.xayy.health.ds.service.DsModelTrainRecordService;
import com.xayy.health.ds.service.DsTaskInfoService;
import com.xayy.health.ds.service.DsTaskParamInfoService;
import com.xayy.health.mgt.model.ModelTrainRecord;
import com.xayy.health.mgt.model.dto.ModelDto;
import com.xayy.health.mgt.model.dto.TelemetryDto;
import com.xayy.health.mgt.model.vo.PreprocessParamVo;
import com.xtck.ha.common.core.constant.HttpStatus;
import com.xtck.ha.common.core.web.controller.BaseController;
import com.xtck.ha.common.core.web.domain.AjaxResult;
import com.xtck.ha.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zhangxa
 */
@RestController
@RequestMapping(value = "/health-mgr-back/v1.0/diagnose")
@Api(tags = "事后诊断")
public class DsDiagnoseController extends BaseController {
    @Autowired
    DsModelTrainRecordService dsModelTrainRecordService;
    @Autowired
    DsDiagnoseService diagnoseService;
    @Autowired
    DsTaskParamInfoService dsTaskParamInfoService;

    /**
     * 模型训练记录列表(分页)
     * @param dsModelTrainRecord 入参
     * @return ResultBody
     */
    @ApiOperation(value = "模型训练记录列表(分页)")
    @GetMapping("/recordPage")
    public AjaxResult page(DsModelTrainRecord dsModelTrainRecord)
    {
        startPage();
        List<DsModelTrainRecord> list = dsModelTrainRecordService.selectTList(dsModelTrainRecord);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setList(list);
        rspData.setMsg("查询成功");
        rspData.setTotal(dsModelTrainRecordService.count(dsModelTrainRecord));
        return AjaxResult.success(rspData);
    }

    /**
     * 获取模型准确度
     * @param modelTrainRecord 模型训练记录
     * @return ResultBody
     */
    @ApiOperation(value = "获取模型准确度")
    @PostMapping("getModelAccuracy")
    public ResultBody getModelAccuracy(@RequestBody DsModelTrainRecord modelTrainRecord) {
        return dsModelTrainRecordService.selectInfo(modelTrainRecord).body();
    }

    /**
     * 获取遥测数据(预处理后)
     * @param telemetryDto 遥测入参
     * @return ResultBody
     */
    @ApiOperation(value = "获取遥测数据(预处理后)")
    @PostMapping("getTelemetry")
    public ResultBody train(@RequestBody TelemetryDto telemetryDto) {
        Map<String, List<DsTelemetryData>> list = diagnoseService.selectTelemetryData(telemetryDto);
        return ResultBody.success(list);
    }

    /**
     * 模型下拉列表
     * @param modelDto 入参
     * @return ResultBody
     */
    @ApiOperation(value = "模型下拉列表")
    @PostMapping("getModel")
    public ResultBody getModel(@RequestBody ModelDto modelDto) {
        return ResultBody.success(dsModelTrainRecordService.getModel(modelDto));
    }

    /**
     * 查询参数在预处理中的信息
     * @param preprocessParamVo 预处理入参
     * @return ResultBody
     */
    @ApiOperation(value = "查询参数在预处理中的信息")
    @PostMapping("/preprocess/param")
    public ResultBody preprocessParam(@RequestBody PreprocessParamVo preprocessParamVo) {
        return dsTaskParamInfoService.preprocessParam(preprocessParamVo).body();
    }

}
